<?php
include 'secure/core.php';
include 'header.php';
include 'left.php'; 
	//calculate the number of rows in table
	$sql_statement = 'SELECT * FROM uploads';
	
	//run the mysql query
	$num_Array = mysql_query($sql_statement);
	
	//total records
	$total_records = mysql_num_rows($num_Array);
	
	//get the page number from the REQUEST / GET
	$page = mysql_real_escape_string($_REQUEST['page']);
	
	//numbers of rows to show on page
	$offset = 10;
	
	//lets calculate the LIMIT for SQL, and save it $from
	if ($page){
		$from 	= ($page * $offset) - $offset;
	}else{
		//if nothing was given in page request, lets load the first page
		$from = 0;	
	}
	 
	$sql_statement = 'SELECT * FROM uploads LIMIT ' . $from . ',' . $offset;
	
	//So, here is the result array which will have all the rows to display on to page
	$resultArray = mysql_query($sql_statement);
?>
<style>
/*---Paging specific styling----*/     
	.paging { padding:10px 0px 0px 0px; text-align:center; font-size:13px;}
	.paging.display{text-align:right;}
	.paging a, .paging span {padding:2px 8px 2px 8px; font-weight :normal}
	.paging span {font-weight:bold; color:#000; font-size:13px; }
	.paging a, .paging a:visited {color:#000; text-decoration:none; border:1px solid #dddddd;}
	.paging a:hover { text-decoration:none; background-color:#6C6C6C; color:#fff; border-color:#000;}
	.paging span.prn { font-size:13px; font-weight:normal; color:#aaa; }
	.paging a.prn, .paging a.prn:visited { border:2px solid #dddddd;}
	.paging a.prn:hover { border-color:#000;}
	.paging p#total_count{color:#aaa; font-size:12px; font-weight: normal; padding-left:18px;}
	.paging p#total_display{color:#aaa; font-size:12px; padding-top:10px;}
		
</style>
		<div id="right">
		<div class="section">
		<?php if($_GET['msg'] == '1') { ?>
		<div class="message green"><span><b>Success</b>: File has been successfully deleted.</span></div>
		<?php } ?>
				<div class="box">
					<div class="title">
						View uploaded files
						<span class="hide"></span>
					</div>
					<div class="content">
						<div class="dataTables_wrapper"><div></div><table cellspacing="0" cellpadding="0" border="0"> 
							<thead> 
								<tr>
								  <th rowspan="1" colspan="1" style="width: 153px; ">Uploaded By</th>
								  <th rowspan="1" colspan="1" style="width: 97px; ">File Name</th>
								  <th rowspan="1" colspan="1" style="width: 171px; ">Date</th>
								  <th rowspan="1" colspan="1" style="width: 158px; ">Actions</th></tr>
							</thead>
							
						<tbody>         <?PHP
                //row number
                $row_number = $from + 1;
                
                //Finally, Lets print all the rows, we've got from sql
                while($rowArray = mysql_fetch_array($resultArray) )
                {
        ?>        
						                <tr> 
									<td><?php echo $files->getUploadersUsername($rowArray['uploaded_by']); ?></td>
									<td><?php echo $rowArray['file_title']; ?></td>
									<td><?php echo $rowArray['created_date']; ?></td>
									<td><a href="delete.php?file=<?php echo $rowArray['string']; ?>">Delete File</a></td>									
								</tr>
								<?php } ?>
						</tbody>
						
				            </table>
				          <?php doPages($offset, 'view_files.php', '', $total_records); ?>

</div>
					        </div>
					</div>
				</div>
			</div>
		</div>

<div id="footer">
			<div class="split">Copyright &#169; 2012 - <?php echo $file_path.$file_name; ?> <a href="index.html">Paid4Upload</a>.</div>
			<div class="split right"><a href="http://www.paid4upload.com/forums">Forums</a> | <a href="tos.php">Terms of Service</a> | <a href="dmca.php">DMCA</a></div>
		</div>
	</div>
</div>

</body>
<?php
     function check_integer($which) {
        if(isset($_REQUEST[$which])){
            if (intval($_REQUEST[$which])>0) {
                //check the paging variable was set or not, 
                //if yes then return its number:
                //for example: ?page=5, then it will return 5 (integer)
                return intval($_REQUEST[$which]);
            } else {
                return false;
            }
        }
        return false;
    }//end of check_integer()

    function get_current_page() {
        if(($var=check_integer('page'))) {
            //return value of 'page', in support to above method
            return $var;
        } else {
            //return 1, if it wasnt set before, page=1
            return 1;
        }
    }//end of method get_current_page()

    function doPages($page_size, $thepage, $query_string, $total=0) {
        
        //per page count
        $index_limit = 1;

        //set the query string to blank, then later attach it with $query_string
        $query='';
        
        if(strlen($query_string)>0){
            $query = "&amp;".$query_string;
        }
        
        //get the current page number example: 3, 4 etc: see above method description
        $current = get_current_page();
        
        $total_pages=ceil($total/$page_size);
        $start=max($current-intval($index_limit/2), 1);
        $end=$start+$index_limit-1;

        echo '<div class="paging">';

        if($current==1) {
            echo '<span class="prn">&lt; Previous</span>&nbsp;';
        } else {
            $i = $current-1;
            echo '<a href="'.$thepage.'?page='.$i.$query.'" class="prn" rel="nofollow" title="go to page '.$i.'">&lt; Previous</a>&nbsp;';
            echo '<span class="prn">...</span>&nbsp;';
        }

        if($start > 1) {
            $i = 1;
            echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a>&nbsp;';
        }

        for ($i = $start; $i <= $end && $i <= $total_pages; $i++){
            if($i==$current) {
                echo '<span>'.$i.'</span>&nbsp;';
            } else {
                echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a>&nbsp;';
            }
        }

        if($total_pages > $end){
            $i = $total_pages;
            echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a>&nbsp;';
        }

        if($current < $total_pages) {
            $i = $current+1;
            echo '<span class="prn">...</span>&nbsp;';
            echo '<a href="'.$thepage.'?page='.$i.$query.'" class="prn" rel="nofollow" title="go to page '.$i.'">Next &gt;</a>&nbsp;';
        } else {
            echo '<span class="prn">Next &gt;</span>&nbsp;';
        }
        
        //if nothing passed to method or zero, then dont print result, else print the total count below:
        if ($total != 0){
            //prints the total result count just below the paging
            echo '<p id="total_count">(total '.$total.' records)</p></div>';
        }}?>
         //end of method doPages()

</html> 